﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using System.Data;
using Entity;

namespace DAL
{
    public class UnitDB : DBAccess
    {
        public IList<Unit> GetAll()
        {
            Unit unit = null;
            IList<Unit> list = null;

            //select all units have visible is true
            string query = "SELECT * FROM Units WHERE Visible = 1";

            this.Connect();

            SqlDataReader rd = this.ExecuteQuery(query, CommandType.Text);
            list = new List<Unit>();

            while (rd.Read())
            {
                unit = new Unit();
                unit.UnitId = rd.GetInt32(0);
                unit.Name = rd.GetString(1);
                unit.Visible = rd.GetBoolean(2);

                list.Add(unit);
            }

            this.Disconnect();

            return list;
        }

        //public DataTable GetAll_unit()
        //{
        //    this.Connect();
        //    string str_select = "SELECT UnitId, Name FROM Units WHERE visible='true'";

        //    SqlDataAdapter da = new SqlDataAdapter(str_select, conn);
        //    DataSet ds = new DataSet();
        //    da.Fill(ds);
        //    return ds.Tables[0];
        //}
    }
}
